'use strict';
 const db = uniCloud.database();

exports.main = async (event, context) => {
  //event为客户端上传的参数
  // console.log('event : ' + event)
  const collection_users = db.collection('users');
  const collection_products =  db.collection('products');
  let user_id=event.user_id;
   let user_icon=event.user_icon;
    let user_name=event.user_name;
  let product_id=event.product_id
  let  res=await collection_products.doc(product_id).update({
	  is_persuaded:true,
	  buyer_id:user_id,
	  buyer_icon:user_icon,
	  buyer_name:user_name
	});
	res=await collection_users.doc(user_id).get()

	let list=res.data[0].my_buys;
	list.push(product_id);

	res=await collection_users.doc(user_id).update({
	  my_buys:list
	});
  //返回数据给客户端
  return {status:2}
};